﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class AdminX_TourCustomization_TourCustomizationAdd : System.Web.UI.UserControl
{
    int nDefault = Support.GetDefaultLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLabelLanguage();
            ValidateControl();
            BindDataWhenEdit();
        }
    }
    private void SetLabelLanguage()
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nDefaultLanguage - 1];

        lblAdult.Text = MultipleLanguage.LBLADULT[nDefaultLanguage - 1];//
        lblChild.Text = MultipleLanguage.LBLCHILD[nDefaultLanguage - 1];

        lblCity.Text = MultipleLanguage.LBL_CITY[nDefaultLanguage-1];
        lblFax.Text = MultipleLanguage.LBL_FAX[nDefaultLanguage - 1];
        lblExpectedDepDate.Text = MultipleLanguage.LBL_EXPECTEDDEPDATE[nDefaultLanguage - 1];
        lblPortOfArrival.Text = MultipleLanguage.LBL_PORTOFARRIVAL[nDefaultLanguage - 1];
        lblVisitationSuggestion.Text = MultipleLanguage.LBL_VISITATIONSUGGESTION[nDefaultLanguage - 1];
        lblTourCategorySuggestion.Text = MultipleLanguage.LBL_TOURCATSUGGESTION[nDefaultLanguage - 1];
        lblGuideSuggestion.Text = MultipleLanguage.LBL_TOURGUIDESUGGESTION[nDefaultLanguage - 1];
        lblGuide.Text = MultipleLanguage.LBL_GUIDELANGUAGE[nDefaultLanguage-1];
        
        lblContactEmail.Text = MultipleLanguage.EMAIL[nDefaultLanguage - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nDefaultLanguage - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nDefaultLanguage - 1];
        
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nDefaultLanguage - 1];
        lblAdult.Text = MultipleLanguage.LBLADULT[nDefaultLanguage - 1];//
        lblChild.Text = MultipleLanguage.LBLCHILD[nDefaultLanguage - 1];
        lblContactEmail.Text = MultipleLanguage.EMAIL[nDefaultLanguage - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nDefaultLanguage - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nDefaultLanguage - 1];
        lblDuration.Text = MultipleLanguage.LBL_DURATION[nDefaultLanguage - 1];
        
        lblPortOfArrival.Text = MultipleLanguage.PORTOFARRIVAL[nDefaultLanguage - 1];
        lblNationality.Text = MultipleLanguage.LBL_NATIONLITY[nDefaultLanguage - 1];
        lblOtherRequest.Text = MultipleLanguage.LBL_MESSAGE[nDefaultLanguage - 1];
        lblPayment.Text = MultipleLanguage.LBL_PAYMENT[nDefaultLanguage - 1];
        lblExpectedDepDate.Text = MultipleLanguage.LBL_STARTDATEBOOKING[nDefaultLanguage - 1];

        lblCustomizationCategory.Text = MultipleLanguage.LBL_TYPEOFTOURCUSTOMIZATION[nDefaultLanguage - 1];
        lblCustomizationCity.Text = MultipleLanguage.LBL_CITY[nDefaultLanguage - 1];
        lblCustomizationHotelOption.Text = MultipleLanguage.LBL_HOTELOPTION[nDefaultLanguage - 1];
        lblCustomizationMeal.Text = MultipleLanguage.MEAL[nDefaultLanguage - 1];
        lblCustomizationRoomType.Text = MultipleLanguage.LBL_ROOMTYPE[nDefaultLanguage - 1];
        lblCustomizationTransport.Text = MultipleLanguage.TRANSPORT[nDefaultLanguage - 1];

        btnBack.Text = MultipleLanguage.BTN_BACK[nDefaultLanguage - 1];
    }
    private void ValidateControl()
    {
    }
    #region Relative Functions
    private void BindDataWhenEdit()
    {
        string sAction = ConvertData.ConvertToString(Request.QueryString[Config.ACTION]);
        try
        {
            if (sAction == Config.ACTION_EDIT)
            {
                int nID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
                if (nID > 0)
                    GetData(nID);
            }
        }
        catch
        {
            string sLink = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURCUSTOMIZATION;
            Response.Redirect(sLink);
        }
    }
    private void GetData(int nID)
     {
        TourCustomization objTourCustomization = new TourCustomization();
        objTourCustomization.LoadById(nID);

        int nDefaultLanguage = Support.GetDefaultLanguage();

        TourDuration objTourCustomizationDuration = new TourDuration();
        if (objTourCustomization.Data.DurationID > 0)
            objTourCustomizationDuration.LoadById(objTourCustomization.Data.DurationID);

        PortOfArrival objPortOfArr = new PortOfArrival();
        if (objTourCustomization.Data.PortOfArrivalID > 0)
            objPortOfArr.LoadById(objTourCustomization.Data.PortOfArrivalID);

        CustomerCountry objCustomerCountry = new CustomerCountry();
        if(objTourCustomization.Data.CountryID > 0 )
            objCustomerCountry.LoadById(objTourCustomization.Data.CountryID);

        TourGuide objTourGuide = new TourGuide();
        if(objTourCustomization.Data.GuideID>0)
            objTourGuide.LoadById(objTourCustomization.Data.GuideID);

        CustomizationCategory objCustCat = new CustomizationCategory();
        DataTable dtbCustCat = new DataTable();
        dtbCustCat = objCustCat.Search(nID);
        Repeater0.DataSource = dtbCustCat;
        Repeater0.DataBind();

        CustomizationCity objCustCity = new CustomizationCity();
        DataTable dtbCustCity = new DataTable();
        dtbCustCity = objCustCity.Search(nID);
        Repeater1.DataSource = dtbCustCity;
        Repeater1.DataBind();

        CustomizationHotelOption objCustHtOpt = new CustomizationHotelOption();
        DataTable dtbCustHtOpt = new DataTable();
        dtbCustHtOpt = objCustHtOpt.Search(nID);
        Repeater2.DataSource = dtbCustHtOpt;
        Repeater2.DataBind();

        CustomizationMeal objCustMeal = new CustomizationMeal();
        DataTable dtbCustMeal = new DataTable();
        dtbCustMeal = objCustMeal.Search(nID);
        Repeater3.DataSource = dtbCustMeal;
        Repeater3.DataBind();

        CustomizationRoomType objCustRoomType = new CustomizationRoomType();
        DataTable dtbCustRoomType = new DataTable();
        dtbCustRoomType = objCustRoomType.Search(nID);
        Repeater4.DataSource = dtbCustRoomType;
        Repeater4.DataBind();

        CustomizationTransport objCustTransport = new CustomizationTransport();
        DataTable dtbCustTransport = new DataTable();
        dtbCustTransport = objCustTransport.Search(nID);
        Repeater5.DataSource = dtbCustTransport;
        Repeater5.DataBind();


        switch (nDefaultLanguage)
        {
            case 1:
                lblValDuration.Text = ConvertData.ConvertToString(objTourCustomizationDuration.Data.DurationDescription1);
                lblValPortOfArrival.Text = ConvertData.ConvertToString(objPortOfArr.Data.PortOfArrivalName1);
                lblValNationality.Text = ConvertData.ConvertToString(objCustomerCountry.Data.CountryName1);
                lblValGuide.Text = objTourGuide.Data.TouristGuideName1;
                break;
            case 2:
                lblValDuration.Text = ConvertData.ConvertToString(objTourCustomizationDuration.Data.DurationDescription2);
                lblValPortOfArrival.Text = ConvertData.ConvertToString(objPortOfArr.Data.PortOfArrivalName2);
                lblValNationality.Text = ConvertData.ConvertToString(objCustomerCountry.Data.CountryName2);
                lblValGuide.Text = objTourGuide.Data.TouristGuideName2;
                break;
            case 3:
                lblValDuration.Text = ConvertData.ConvertToString(objTourCustomizationDuration.Data.DurationDescription3);
                lblValPortOfArrival.Text = ConvertData.ConvertToString(objPortOfArr.Data.PortOfArrivalName3);
                lblValNationality.Text = ConvertData.ConvertToString(objCustomerCountry.Data.CountryName3);
                lblValGuide.Text = objTourGuide.Data.TouristGuideName3;
                break;

        }
        lblValAdult.Text = ConvertData.ConvertToString(objTourCustomization.Data.Adults);
        lblValChild.Text = ConvertData.ConvertToString(objTourCustomization.Data.Children);//
        int nStatus = 0;
        nStatus = ConvertData.ConvertToInt(objTourCustomization.Data.Status);
        lblValContactAddress.Text = ConvertData.ConvertToString(objTourCustomization.Data.Address);//
        lblValContactEmail.Text = ConvertData.ConvertToString(objTourCustomization.Data.Email);//
        lblValContactFullname.Text = ConvertData.ConvertToString(objTourCustomization.Data.FullName); //
        txtContactPhone.Text = ConvertData.ConvertToString(objTourCustomization.Data.Telephone);//
        lblValOtherRequest.Text = ConvertData.ConvertToString(objTourCustomization.Data.OtherRequest);
        Payment objPayment = new Payment();
        if(objTourCustomization.Data.PaymentID>0)
            objPayment.LoadById(objTourCustomization.Data.PaymentID);
        lblValPayment.Text = ConvertData.ConvertToString(objPayment.Data.Description);

        lblValFax.Text = ConvertData.ConvertToString(objTourCustomization.Data.Fax);
        lblValCity.Text = ConvertData.ConvertToString(objTourCustomization.Data.CityName);
        lblValExpectedDepDate.Text = ConvertData.ConvertIntToDatetimeString(objTourCustomization.Data.ExpectedDepartureDate);
        lblValVisitationSuggestion.Text = ConvertData.ConvertToString(objTourCustomization.Data.VisitationSuggestion);
        lblValTourCategorySuggestion.Text = ConvertData.ConvertToString(objTourCustomization.Data.TourCategorySuggestion);
        lblValGuideSuggestion.Text = ConvertData.ConvertToString(objTourCustomization.Data.GuideSuggestion);

        if (objTourCustomization.Data.EverHeard == 1)
        {
            lblEverHeard.Text = MultipleLanguage.LBL_EVERHEARD_BACKEND[nDefault -1] + "Internet";
        }
        else if (objTourCustomization.Data.EverHeard == 2)
        {
            lblEverHeard.Text = MultipleLanguage.LBL_EVERHEARD_BACKEND[nDefault - 1] + "Friends";
        }
        else if (objTourCustomization.Data.EverHeard == 3)
        {
            lblEverHeard.Text = MultipleLanguage.LBL_EVERHEARD_BACKEND[nDefault - 1] + "Magazine";
        }
        else
        {
            lblEverHeard.Text = MultipleLanguage.LBL_EVERHEARD_BACKEND[nDefault -1] + "other position choice";
        }

        int Result = objTourCustomization.UpdateStatus(nID, EnumeType.ACTIVE);
    }
    #endregion

    #region Click Events
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect(Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURCUSTOMIZATION);
    }
    #endregion

    protected void Repeater0_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            //CustomizationCategory
            switch (nDefault)
            {
                case 1:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomization1"));
                    break;
                case 2:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomization1"));
                    break;
                case 3:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TypeOfCustomization1"));
                    break;
            }
        }
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            //CustomizationCity
            
            switch (nDefault)
            {
                case 1:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName1"));
                    break;
                case 2:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName1"));
                    break;
                case 3:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "CityName1"));
                    break;
            }
        }
    }
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            //CustomizationHotelOption
            
            switch (nDefault)
            {
                case 1:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title1"));
                    break;
                case 2:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title2"));
                    break;
                case 3:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title3"));
                    break;
            }
        }
    }
    protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            //CustomizationMeal
            
            switch (nDefault)
            {
                case 1:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Name1"));
                    break;
                case 2:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Name2"));
                    break;
                case 3:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Name3"));
                    break;
            }
        }
    }
    protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");

            //CustomizationRoomType
            switch (nDefault)
            {
                case 1:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));
                    break;
                case 2:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2"));
                    break;
                case 3:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3"));
                    break;
            }
        }
    }
    protected void Repeater5_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblID = (Label)e.Item.FindControl("lblID");
            //CustomizationTransport
            
            switch (nDefault)
            {
                case 1:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TransportName1"));
                    break;
                case 2:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TransportName2"));
                    break;
                case 3:
                    lblID.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TransportName3"));
                    break;
            }
        }
    }
}